package com.dlc.shop.delivery.api.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dlc.shop.bean.model.OrderVirtualVerifyLog;
import com.dlc.shop.bean.vo.OrderVirtualVerifyLogVO;
import com.dlc.shop.common.response.ServerResponseEntity;
import com.dlc.shop.common.util.PageParam;
import com.dlc.shop.service.OrderVirtualVerifyLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 订单虚拟商品核销记录
 *
 * @author LGH
 * @date 2023-03-07 16:48:15
 */
@RestController
@RequestMapping("/p/orderVirtualVerifyLog")
@Tag(name = "订单虚拟商品核销记录")
@AllArgsConstructor
public class OrderVirtualVerifyLogController {

    private final OrderVirtualVerifyLogService orderVirtualVerifyLogService;

    @GetMapping("/page")
    @Operation(summary = "获取订单虚拟商品核销记录列表", description = "分页获取订单虚拟商品核销记录列表")
    public ServerResponseEntity<IPage<OrderVirtualVerifyLog>> getOrderVirtualVerifyLogPage(PageParam<OrderVirtualVerifyLog> page, OrderVirtualVerifyLog orderVirtualVerifyLog) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.page(page, new LambdaQueryWrapper<OrderVirtualVerifyLog>()));
    }


    @GetMapping("/info/{id}")
    @Operation(summary = "获取订单虚拟商品核销记录", description = "根据id获取订单虚拟商品核销记录")
    @Parameter(name = "id", description = "订单虚拟商品核销记录", required = true)
    public ServerResponseEntity<OrderVirtualVerifyLog> getById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.getById(id));
    }

    @GetMapping("/listByWriteOffCode")
    @Operation(summary = "根据核销码获取订单虚拟商品核销记录列表", description = "根据核销码获取订单虚拟商品核销记录列表")
    @Parameter(name = "writeOffCode", description = "核销码", required = true)
    public ServerResponseEntity<List<OrderVirtualVerifyLog>> listByWriteOffCode(@RequestParam("writeOffCode") String writeOffCode) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.listByWriteOffCode(writeOffCode));
    }

    @GetMapping("/getByOrderNumber")
    @Operation(summary = "根据订单编号获取订单虚拟商品核销记录信息", description = "根据订单编号获取订单虚拟商品核销记录信息")
    @Parameter(name = "orderNumber", description = "订单编号", required = true)
    public ServerResponseEntity<OrderVirtualVerifyLogVO> getByOrderNumber(@RequestParam("orderNumber") String orderNumber) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.getByOrderNumber(orderNumber));
    }



    @PostMapping
    @PreAuthorize("@pms.hasPermission('seckill:orderVirtualVerifyLog:save')")
    @Operation(summary = "保存订单虚拟商品核销记录", description = "保存订单虚拟商品核销记录")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid OrderVirtualVerifyLog orderVirtualVerifyLog) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.save(orderVirtualVerifyLog));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('seckill:orderVirtualVerifyLog:update')")
    @Operation(summary = "更新订单虚拟商品核销记录", description = "更新订单虚拟商品核销记录")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid OrderVirtualVerifyLog orderVirtualVerifyLog) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.updateById(orderVirtualVerifyLog));
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('seckill:orderVirtualVerifyLog:delete')")
    @Operation(summary = "删除订单虚拟商品核销记录", description = "根据订单虚拟商品核销记录id删除订单虚拟商品核销记录")
    @Parameter(name = "id", description = "订单虚拟商品核销记录", required = true)
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ServerResponseEntity.success(orderVirtualVerifyLogService.removeById(id));
    }
}
